import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver

class MyPostsTest:
    url=""
    driver=""

    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
    #在我的帖子页功能测试
    def MyPosts(self):
        #首页-点击用户头像-点击我的帖子
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        #time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_profile").click()
        #是否有昵称
        self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname")
        #是否有头像
        self.driver.find_element(By.CSS_SELECTOR,"#profile_avatar")
        #是否有注册日期
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(3) > svg")
        #是否有发帖数
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(1) > svg")
        #是否有邮箱
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(2) > svg")
        #是否由个人简介
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div > h2")
        #是否有帖子浏览量
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(1) > svg")
        #是否有帖子点赞数
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(2) > svg > path:nth-child(2)")
        #是否有帖子评论数
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(3) > svg > path:nth-child(4)")
        ForumDriver.getScreenShot()
        #点击帖子标题是否可以跳转到帖子详情页
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a").click()
        #如果跳转到详情页，则有"最新回复"元素
        print(self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div:nth-child(2) > h3").text)
        ForumDriver.getScreenShot()

    #网友的帖子页
    def InternetUserPosts(self):
        #首页-点击帖子标题-点击网友昵称，进入网友的帖子页
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div:nth-child(1) > div.col-3.card > div > h3").click()
        #是否有昵称
        self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname")
        #是否有头像
        self.driver.find_element(By.CSS_SELECTOR,"#profile_avatar")
        #是否有注册日期
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(3) > svg")
        #是否有发帖数
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(1) > svg")
        #是否有邮箱
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(2) > svg")
        #是否由个人简介
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div > h2")
        #是否有帖子浏览量
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(1) > svg")
        #是否有帖子点赞数
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(2) > svg > path:nth-child(2)")
        #是否有帖子评论数
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(3) > svg > path:nth-child(4)")
        ForumDriver.getScreenShot()













